package qlsl.androiddesign.http.service.subservice;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.text.TextUtils;
import android.widget.EditText;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alipay.android.phone.mrpc.core.s;
import com.qlsl.androiddesign.kuaiwa.R;

import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.entity.otherentity.Entity;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.util.commonutil.Log;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 发布求职模块 <br/>
 * 
 */
public class PostJobService extends BaseService {

	private static String className = getClassName(PostJobService.class);

	public static void insertAdvertises(final String type,
			final List<HashMap<String, Object>> list,
			final FunctionView<?> functionView, final HttpListener listener) {
		final HttpHandler handler = getHandler(functionView, listener,
				className, "insertAdvertises");
		new HandlerThread(className, "insertAdvertises") {
			public void run() {
				HttpProtocol protocol = new HttpProtocol();
				protocol.setMethod("sendadvertises");
				try {
					String[] keys = new String[] { "title", "province",
							"drivertime", "pay", "workhistory", "ability",
							"playdirection", "welfare", "mobile" };
					for (int index = 0, count = list.size(); index < count; index++) {// childIndex过滤前2个
						HashMap<String, Object> map = list.get(index);
						if (index == 1) {
							String pro_city = (String) map.get("value");
							String[] splits = pro_city.split(" ");

							String pro = splits[0];
							String city = "";
							if (splits.length > 2) {
								city = splits[1];
							}

							protocol.addParam("province", pro);
							protocol.addParam("city", city);
							continue;
						}
						protocol.addParam(keys[index], map.get("value"));

					}

					protocol.addParam("type", type);

					JSONObject jo = protocol.post();

					Log.e("qlsl", jo);

					if (isDataInvalid(jo, handler, protocol)) {
						return;
					}

					handler.sendMessage(protocol,
							WhatConstant.WHAT_NET_DATA_SUCCESS, "发布成功");
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendMessage(protocol, WhatConstant.WHAT_EXCEPITON,
							e);
				}
			};
		}.start();
	}
}
